﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:rtd="http://schemas.commerceserver.net/2013/01/foundation/RequestTemplateDefinition"
           targetNamespace="http://schemas.commerceserver.net/2013/01/foundation/RequestTemplateDefinition">

  <xs:element name="RequestTemplates" type="rtd:RequestTemplatesType">
    <xs:key name="RequestTemplateKey">
      <xs:selector xpath=".//rtd:RequestTemplate"/>
      <xs:field xpath="@id"/>
    </xs:key>
  </xs:element>

  <!-- RequestTemplate Node -->
  <xs:complexType name="RequestTemplatesType">
    <xs:sequence>
      <xs:element maxOccurs="1" minOccurs="0" name="clear" />
      <xs:element maxOccurs="unbounded" minOccurs="0" name="RequestTemplate" type="rtd:RequestTemplateType">
        <xs:key name="RequestTemplateOperationId">
          <xs:selector xpath=".//rtd:Operation | .//rtd:Operation/rtd:Operation"/>
          <xs:field xpath="@id" />
        </xs:key>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- RequestTemplate Node -->
  <xs:complexType name="RequestTemplateType">
    <xs:sequence>
      <xs:element minOccurs="0" name="Descriptions" type="rtd:DescriptionsType">
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Operation" type="rtd:OperationType">
      </xs:element>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required" />
    <xs:attribute name="group" type="xs:string" use="required" />
    <xs:attribute name="cached" type="xs:boolean" use="optional" />
    <xs:attribute name="cacheExpiration" type="xs:string" use="optional" />
    <xs:attribute name="containsSensitiveData" type="xs:boolean" use="optional" />
  </xs:complexType>

  <!-- Descriptions Node -->
  <xs:complexType name="DescriptionsType">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" name="Description">
        <xs:complexType>
          <xs:attribute name="value" type="xs:string" use="required" />
          <xs:attribute name="culture" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- Operation Node -->
  <xs:complexType name="OperationType">
    <xs:sequence>
      <xs:element minOccurs="0" name="Search" type="rtd:SearchType">
        <xs:key name="SearchArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="Sort" type="rtd:SortType">
        <xs:key name="SortArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="Options" type="rtd:OptionsType">
        <xs:key name="OptionsArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="PropertiesToSet" type="rtd:PropertiesToSetType">
        <xs:key name="PropertiesToSetArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="PropertiesToReturn" type="rtd:PropertiesToReturnType">
        <xs:key name="PropertiesToReturnArgumentName">
          <xs:selector xpath=".//rtd:Property"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Operation" type="rtd:RelatedOperationType">
      </xs:element>
    </xs:sequence>
    <xs:attribute name="id" type="xs:unsignedByte" use="required" />
    <xs:attribute name="builder" type="rtd:operationBuilder" use="required" />
    <xs:attribute name="entity" type="xs:string" use="required" />
    <xs:attribute name="operationName" type="xs:string" use="optional" />
    <xs:attribute name="commerceArea" type="rtd:commerceServerArea" use="optional" />
  </xs:complexType>

  <!-- Search Node -->
  <xs:complexType name="SearchType">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Argument">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string" use="required" />
          <xs:attribute name="value" type="xs:string" use="optional" />
          <xs:attribute name="customTypeConverter" type="xs:string" use="optional" />
          <xs:attribute name="useMetadataTypeConverter" type="xs:boolean" use="optional" default="true" />
          <xs:attribute name="alias" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="builder" type="rtd:searchBuilder" use="optional" />
  </xs:complexType>

  <!-- Sort Node -->
  <xs:complexType name="SortType">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="unbounded" name="Argument">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string" use="required" />
          <xs:attribute name="value" type="rtd:sortDirection" use="optional" />
          <xs:attribute name="customTypeConverter" type="xs:string" use="optional" />
          <xs:attribute name="useMetadataTypeConverter" type="xs:boolean" use="optional" default="true" />
          <xs:attribute name="alias" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- Sort Direction Enumeration Simple Type -->
  <xs:simpleType name="sortDirection">
    <xs:annotation>
      <xs:documentation>
        These defines the supported sorting types.
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration id="Ascending" value = "Ascending"/>
      <xs:enumeration id="Default" value = "Default"/>
      <xs:enumeration id="Descending" value = "Descending"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- Options Node -->
  <xs:complexType name="OptionsType">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Argument">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string" use="required" />
          <xs:attribute name="value" type="xs:string" use="optional" />
          <xs:attribute name="customTypeConverter" type="xs:string" use="optional" />
          <xs:attribute name="useMetadataTypeConverter" type="xs:boolean" use="optional" default="true" />
          <xs:attribute name="alias" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="builder" type="rtd:optionsBuilder" use="optional" />
  </xs:complexType>

  <!-- PropertiesToSet Node -->
  <xs:complexType name="PropertiesToSetType">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="unbounded" name="Argument">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string" use="required" />
          <xs:attribute name="value" type="xs:string" use="optional" />
          <xs:attribute name="customTypeConverter" type="xs:string" use="optional" />
          <xs:attribute name="useMetadataTypeConverter" type="xs:boolean" use="optional" default="true" />
          <xs:attribute name="alias" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- PropertiesToReturn Node -->
  <xs:complexType name="PropertiesToReturnType">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="unbounded" name="Property">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- RelatedOperation Node -->
  <xs:complexType name="RelatedOperationType">
    <xs:sequence>
      <xs:element minOccurs="0" name="Search" type="rtd:SearchType">
        <xs:key name="RelatedSearchArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="Sort" type="rtd:SortType">
        <xs:key name="RelatedSortArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="Options" type="rtd:OptionsType">
        <xs:key name="RelatedOptionsArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="PropertiesToSet" type="rtd:PropertiesToSetType">
        <xs:key name="RelatedPropertiesToSetArgumentName">
          <xs:selector xpath=".//rtd:Argument"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" name="PropertiesToReturn" type="rtd:PropertiesToReturnType">
        <xs:key name="RelatedPropertiesToReturnArgumentName">
          <xs:selector xpath=".//rtd:Property"/>
          <xs:field xpath="@name"/>
        </xs:key>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Operation" type="rtd:RelatedOperationType">
      </xs:element>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required" />
    <xs:attribute name="builder" type="rtd:relatedOperationBuilder" use="required" />
    <xs:attribute name="entity" type="xs:string" use="required" />
    <xs:attribute name="relationshipName" type="xs:string" use="required" />
    <xs:attribute name="operationName" type="xs:string" use="optional" />
    <xs:attribute name="commerceArea" type="rtd:commerceServerArea" use="optional" />
  </xs:complexType>

  <xs:simpleType name="builtInOperationBuilder">
    <xs:restriction base="xs:string">
      <xs:enumeration id="CreateOperationBuilder" value="CreateOperationBuilder" />
      <xs:enumeration id="DeleteOperationBuilder" value="DeleteOperationBuilder" />
      <xs:enumeration id="QueryOperationBuilder" value="QueryOperationBuilder" />
      <xs:enumeration id="UpdateOperationBuilder" value="UpdateOperationBuilder" />
      <xs:enumeration id="LogonOperationBuilder" value="LogonOperationBuilder" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="operationBuilder">
    <xs:annotation>
      <xs:documentation>Defines the builder that will be used to construct the operation.</xs:documentation>
    </xs:annotation>
    <xs:union memberTypes="rtd:builtInOperationBuilder xs:string" />
  </xs:simpleType>

  <xs:simpleType name="builtInRelatedOperationBuilder">
    <xs:annotation>
      <xs:documentation>Defines the builder that will be used to construct the related operation.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration id="CreateRelationshipOperationBuilder" value="CreateRelationshipOperationBuilder" />
      <xs:enumeration id="DeleteRelationshipOperationBuilder" value="DeleteRelationshipOperationBuilder" />
      <xs:enumeration id="QueryRelationshipOperationBuilder" value="QueryRelationshipOperationBuilder" />
      <xs:enumeration id="UpdateRelationshipOperationBuilder" value="UpdateRelationshipOperationBuilder" />
      <xs:enumeration id="CreateRelatedOperationBuilder" value="CreateRelatedOperationBuilder" />
      <xs:enumeration id="DeleteRelatedOperationBuilder" value="DeleteRelatedOperationBuilder" />
      <xs:enumeration id="QueryRelatedOperationBuilder" value="QueryRelatedOperationBuilder" />
      <xs:enumeration id="RelatedOperationBuilder" value="RelatedOperationBuilder" />
      <xs:enumeration id="UpdateRelatedOperationBuilder" value="UpdateRelatedOperationBuilder" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="relatedOperationBuilder">
    <xs:annotation>
      <xs:documentation>Defines the builder that will be used to construct the related operation.</xs:documentation>
    </xs:annotation>
    <xs:union memberTypes="rtd:builtInRelatedOperationBuilder xs:string" />
  </xs:simpleType>

  <xs:simpleType name="builtInSearchBuilder">
    <xs:restriction base="xs:string">
      <xs:enumeration id="CatalogFullTextSearchCriteriaBuilder" value = "CatalogFullTextSearchCriteriaBuilder"/>
      <xs:enumeration id="ClaimsSearchCriteriaBuilder" value = "ClaimsSearchCriteriaBuilder"/>
      <xs:enumeration id="ModelSearchCriteriaBuilder" value = "ModelSearchCriteriaBuilder"/>
      <xs:enumeration id="SecurityAnswerSearchCriteriaBuilder" value = "SecurityAnswerSearchCriteriaBuilder"/>
      <xs:enumeration id="SiteContentSearchCriteriaBuilder" value = "SiteContentSearchCriteriaBuilder"/>
      <xs:enumeration id="ValidateUserSearchCriteriaBuilder" value = "ValidateUserSearchCriteriaBuilder"/>
      <xs:enumeration id="LogonSearchBuilder" value = "LogonSearchBuilder"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="searchBuilder">
    <xs:annotation>
      <xs:documentation>Defines the builder that will be used to construct the operation search criteria.</xs:documentation>
    </xs:annotation>
    <xs:union memberTypes="rtd:builtInSearchBuilder xs:string" />
  </xs:simpleType>

  <xs:simpleType name="builtInOptionsBuilder">
    <xs:restriction base="xs:string">
      <xs:enumeration id="BasketQueryOptionsBuilder" value = "BasketQueryOptionsBuilder"/>
      <xs:enumeration id="BasketUpdateOptionsBuilder" value = "BasketUpdateOptionsBuilder"/>
      <xs:enumeration id="CatalogCreateOptionsBuilder" value = "CatalogCreateOptionsBuilder"/>
      <xs:enumeration id="CatalogDeleteOptionsBuilder" value = "CatalogDeleteOptionsBuilder"/>
      <xs:enumeration id="CatalogUpdateOptionsBuilder" value = "CatalogUpdateOptionsBuilder"/>
      <xs:enumeration id="CreateOptionsBuilder" value = "CreateOptionsBuilder"/>
      <xs:enumeration id="DeleteOptionsBuilder" value = "DeleteOptionsBuilder"/>
      <xs:enumeration id="QueryOptionsBuilder" value = "QueryOptionsBuilder"/>
      <xs:enumeration id="UpdateOptionsBuilder" value = "UpdateOptionsBuilder"/>
      <xs:enumeration id="LogonOptionsBuilder" value = "LogonOptionsBuilder"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="optionsBuilder">
    <xs:annotation>
      <xs:documentation>Defines the builder that will be used to construct the operation options.</xs:documentation>
    </xs:annotation>
    <xs:union memberTypes="rtd:builtInOptionsBuilder xs:string" />
  </xs:simpleType>

  <xs:simpleType name="commerceServerArea">
    <xs:restriction base="xs:string">
      <xs:enumeration id="Catalog" value="Catalog"/>
      <xs:enumeration id="Profiles" value="Profiles"/>
      <xs:enumeration id="Orders" value="Orders"/>
      <xs:enumeration id="Marketing" value="Marketing"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>